package com.manage.server.controller.admin;

import com.manage.dto.RoleDTO;
import com.manage.dto.add.RoleAddDTO;
import com.manage.dto.update.RoleUpdateDTO;
import com.manage.result.PageResult;
import com.manage.server.service.RoleService;
import com.manage.vo.RoleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.manage.result.Result;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @PostMapping
    public Result add(@RequestBody RoleAddDTO roleAddDTO) {
        roleService.save(roleAddDTO);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        roleService.removeById(id);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody RoleUpdateDTO roleUpdateDTO) {
        roleService.updateById(roleUpdateDTO);
        return Result.success();
    }

    /**
     * 多项分类分页查询
     * @param roleDTO
     * @return
     */
    @PostMapping("/page")
    public PageResult<RoleVO> findRole(@RequestBody RoleDTO roleDTO) {
        return roleService.findRoleByPage(roleDTO);
    }
}